package com.manager.core.module.manager.service;


import com.manager.commons.utils.StringUtil;
import com.manager.commons.mybatis.dao.GenericDao;
import com.manager.commons.mybatis.service.GenericService;
import com.manager.core.module.manager.dao.PlatformParameterDao;
import com.manager.core.module.manager.entity.PlatformParameter;
import com.manager.core.web.json.AjaxJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * PlatformUserLogService
 *
 * @author H
 * @version 1.0
 */
@Service
public class PlatformParameterService extends GenericService<PlatformParameter> {

    @Autowired
    private PlatformParameterDao jdbcDao;

    @Override
    public GenericDao<PlatformParameter> getDao() {
        return jdbcDao;
    }

    /**
     * 保存
     *
     * @param params
     * @return
     */
    @Override
    public AjaxJson save(Map<String, Object> params) {
        try {
            if (null != params) {
                int f = 0;
                String _id = String.valueOf(params.get("_id"));
                if (StringUtil.isEmpty(_id)) {
                    f = insertMap(params);
                } else {
                    f = updateMap(params);
                }
                return new AjaxJson(f, "保存".concat(f > 0 ? "成功" : "失败"));
            }
            return new AjaxJson("参数错误");
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        return new AjaxJson("异常错误，请稍后再试");
    }
}